package mo.qmul.gemom;

import javax.swing.JPanel;
import java.awt.Frame;
import java.awt.BorderLayout;
import javax.swing.JDialog;
import java.awt.Dimension;
import java.util.Vector;

import javax.swing.JFrame;
import javax.swing.JScrollPane;
import javax.swing.JTable;
import javax.swing.table.DefaultTableModel;
/** COPYRIGHT DISCLAIMER
 * Synopsis: All the source codes presented in this document are intellectual
 * properties of Queen Mary, University of London.
 * 
 * @year 2010
 * @author Peng Jiang, John Bigham, Jiayi Wu Jinfu Wang------------QMUL
 * @version 1.0 
 * */
public class TopicDialog extends JDialog {

	private static final long serialVersionUID = 1L;
	private JPanel jContentPane = null;
	private JScrollPane jScrollPane_spane = null;
	private JTable jTable_topic = null;
	
	private TopicData td;

	/**
	 * @param owner
	 */
	public TopicDialog(JFrame owner, TopicData tp) {
		super(owner);
		
		td=tp;
		
		initialize();
	}

	/**
	 * This method initializes this
	 * 
	 * @return void
	 */
	private void initialize() {
		this.setSize(328, 317);
		this.setContentPane(getJContentPane());
		
		this.setTitle(td.getTopic()+"@"+td.getNamespace());
		this.addWindowListener(new java.awt.event.WindowAdapter() {
			public void windowClosing(java.awt.event.WindowEvent e) {
				
				closeAction();
			}
		});
		
		
		
	}
	
	
	private void closeAction(){
		
		this.hide();
		this.dispose();
	}
	
	

	/**
	 * This method initializes jContentPane
	 * 
	 * @return javax.swing.JPanel
	 */
	private JPanel getJContentPane() {
		if (jContentPane == null) {
			jContentPane = new JPanel();
			jContentPane.setLayout(new BorderLayout());
			jContentPane.add(getJScrollPane_spane(), BorderLayout.CENTER);
		}
		return jContentPane;
	}

	/**
	 * This method initializes jScrollPane_spane	
	 * 	
	 * @return javax.swing.JScrollPane	
	 */
	private JScrollPane getJScrollPane_spane() {
		if (jScrollPane_spane == null) {
			jScrollPane_spane = new JScrollPane();
			jScrollPane_spane.setViewportView(getJTable_topic());
		}
		return jScrollPane_spane;
	}

	/**
	 * This method initializes jTable_topic	
	 * 	
	 * @return javax.swing.JTable	
	 */
	private JTable getJTable_topic() {
		if (jTable_topic == null) {
			
			String[] colName={"Time","Value"};
			DefaultTableModel model= new DefaultTableModel(colName,0);
			
			
			Vector<Field> vF= td.getData();
			
			for(int i=0; i< vF.size(); i++)
			{
				Object[] rowData= new Object[2];
				
				rowData[0]=vF.get(i).getKey();
				//String v=""+
				rowData[1]=vF.get(i).getValue();
				
				model.addRow(rowData);
			}
			
			jTable_topic = new JTable(model);
		}
		return jTable_topic;
	}

}  //  @jve:decl-index=0:visual-constraint="304,112"
